<template>
  <el-card v-for="(item, index) in showdata" :key="index" class="box-card">
    <template #header>
      <div class="card-header">
        <div v-html="item.paperName"></div>
      </div>
    </template>
    <el-button style="float: right" type="primary" @click="jump(item.id)"
      >查看</el-button
    >
    <br />
    <div v-html="'学科：' + item.subjectName"></div>
    <br />
    <div v-html="'试卷类型：' + item.paperType"></div>
    <br />
    <div v-html="'批改状态：' + item.status"></div>
    <br />
    <div v-html="'得分：' + item.paperScore"></div>
    <br />
  </el-card>
  <el-pagination
    v-model:currentPage="showform.pageIndex"
    v-model:page-size="showform.pageSize"
    :page-sizes="[5, 10, 20, 50]"
    :small="small"
    :disabled="disabled"
    :background="background"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
</template>

<script setup>
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import router from '@/router'
import { mydata } from '@/api/user'
import { getexamdata } from '@/api/paper'
const papermap = ref([
  '未知',
  '固定试卷',
  '未知',
  '未知',
  '时段试卷',
  '已批改',
  '任务试卷'
])
const statusmap = ref(['未知', '待批改', '已批改'])
//  获取个人信息
const mdata = ref({})
const inimydata = async () => {
  const res = await mydata()
  mdata.value = res.data.data
  //   console.log(mdata.value)
}
//  获取考试记录
const edata = ref([])
const iniedata = async () => {
  const queryForm = ref({
    pageIndex: 1,
    pageSize: 10000
  })
  let res = await getexamdata(queryForm.value).then()
  res = res.data.data.list
  for (let i = 0; i < res.length; i++) {
    if (res[i].userName === mdata.value.userName) {
      edata.value.push(res[i])
    }
    if (i === res.length - 1) getshowdata()
  }
  total.value = edata.value.length
  //   console.log(edata.value)
}
// 获取展示信息
const showdata = ref([])
const showform = ref({
  pageIndex: 1,
  pageSize: 5
})
const total = ref()
const getshowdata = async () => {
  let temp = []
  for (
    let i = (showform.value.pageIndex - 1) * showform.value.pageSize;
    i < showform.value.pageSize * showform.value.pageIndex;
    i++
  ) {
    if (edata.value[i]) temp.push(edata.value[i])
  }
  for (let i = 0; i < temp.length; i++) {
    temp[i].status = statusmap.value[temp[i].status]
    temp[i].paperType = papermap.value[temp[i].paperType]
  }
  showdata.value = temp
  console.log('showdata', showdata.value)
}

const handleSizeChange = (pageSize) => {
  showform.value.pageIndex = 1
  showform.value.pageSize = pageSize
  getshowdata()
}

const handleCurrentChange = (pagenum) => {
  showform.value.pageIndex = pagenum
  getshowdata()
}

const init = () => {
  inimydata()
  iniedata()
}
init()

const jump = (id) => {
  router.push({ name: 'sckeck', params: { id: id } })
}
</script>

<style lang="scss" scoped>
.header {
  padding-bottom: 16px;
  box-sizing: border-box;
}
</style>
